<?php 
if($pxsj['status']=="已考"){
?>
<base href="<?php echo XXF_HTTP?>" />
<meta charset="utf-8">
<script>
alert("本场考试已结束！");
location.href="pxexam";
</script>
<?php 
    exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<base href="<?php echo XXF_HTTP?>" />
<meta charset="utf-8">
<title>重庆煤矿安全培训考试中心考核系统</title>
<style type="text/css">
*{margin:0px;padding:0px;-moz-box-sizing: border-box;  /*Firefox3.5+*/-webkit-box-sizing: border-box; /*Safari3.2+*/-o-box-sizing: border-box; /*Opera9.6*/-ms-box-sizing: border-box; /*IE8*/box-sizing: border-box;}
.contain{width:800px;margin:0 auto;background-color:#E0F2FE;}
.head{width:800px;height:87px;background:url(img/logol.png);}
.info{width:200px;float:right;background-color:#BCE1F1;}
.main{width:600px;}
.dati{width:18px;height:18px;float:left;border:1px solid #333 ;}
.dati:hover{background-color:#aaa;}
.yida{background-color:#aaa;}
.jiaojuan{width:100px;height:40px;font-size:25px;margin-top:10px;margin-bottom:10px;}
.zuoda{text-align:right;}
.bigger{width:25px;height:25px;}
hr{ margin-top: 10px;margin-bottom:10px;}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="js/jquery.xxfset.js?r=<?php echo rand()?>"></script>
</head>
<body>
<div class="contain"><!-- 容器 -->
	<div class="head"><!-- 头部 -->
		<div class="head" style="position: fixed;text-align:center;">
			
		</div>
	</div>
	<div class="info">
		<div class="info" style="position: fixed;text-align: center;font-weight:900;"><!-- 悬浮的个人信息栏 -->
			<div id="sytime" style="margin-top:10px;margin-bottom:10px;color:red;font-size:22px;"></div><!-- 剩余时间 -->
			<div><img alt="<?php echo $pxxy['puname']?>" src="uploader/xueyuanimg/<?php echo $pxxy['idcard']?>.jpg" width="100px" height="120px" ></div>
			<div><?php echo $pxxy['puname']?><br><?php echo $pxxy['idcard']?></div>
			<hr>
			作答情况
			<div style="width: 180px;margin:0 auto;cursor:pointer;" ><!-- 答题情况开始 -->
				<div style="text-align: left;">判断题</div>
				<?php
				$i=1;
				foreach ($pxst as $row){
				    if($i==51)echo "<div style='text-align: left;'>单选题</div>";
				    if($i++==91)echo "<div style='text-align: left;'>多选题</div>";
				    ?><div onclick="mao('<?php echo $row['id']?>')" class="dati <?php echo $row["daan"]==""?"":"yida"?>" id="dati_<?php echo $row['id']?>"></div><?php 
				}
				?>
			</div><!-- 答题情况结束 -->
			<div><button class="jiaojuan" onclick="jiaojuan()">交 卷</button></div>
		</div>
	</div>
	<div class="main" style="padding:10px;font-size:22px;">
		<?php 
		$i=1;
		$duoxuanstr="id";
		foreach ($pxst as $row){
		    if($i<=50){
		        echo "[".$row["tixing"]."] ".$i."、".$row['timian']."<br><br>";
		        echo "<div class='zuoda' id='mao_".$row['id']."'>";
		        echo "<input class='bigger' value='√' type='radio' name='p_".$row["id"]."' ".($row['daan']=="√"?"checked":"")." onclick='dati(this)'>√ ";
		        echo "<input class='bigger' value='×' type='radio' name='p_".$row["id"]."' ".($row['daan']=="×"?"checked":"")." onclick='dati(this)'>×";
		        echo "</div>";
		    }else if($i<=90){
		        echo "[".$row["tixing"]."] ".$i."、".$row['timian']."<br><br>";
		        $str=preg_replace('/A/','A ',$row["xuanxiang"],1);
		        $str=preg_replace('/B/','<br>B ',$str,1);
		        $str=preg_replace('/C/','<br>C ',$str,1);
		        echo $str;
		        echo "<div class='zuoda' id='mao_".$row['id']."'>";
		        echo "<input class='bigger' value='A' type='radio' name='p_".$row["id"]."' ".($row['daan']=="A"?"checked":"")." onclick='dati(this)'>A ";
		        echo "<input class='bigger' value='B' type='radio' name='p_".$row["id"]."' ".($row['daan']=="B"?"checked":"")." onclick='dati(this)'>B ";
		        echo "<input class='bigger' value='C' type='radio' name='p_".$row["id"]."' ".($row['daan']=="C"?"checked":"")." onclick='dati(this)'>C ";
		        echo "</div>";
		    }else{
		        echo "[".$row["tixing"]."] ".$i."、".$row['timian']."<br><br>";
		        $str=preg_replace('/A/','A ',$row["xuanxiang"],1);
		        $str=preg_replace('/B/','<br>B ',$str,1);
		        $str=preg_replace('/C/','<br>C ',$str,1);
		        $str=preg_replace('/D/','<br>D ',$str,1);
		        $str=preg_replace('/E/','<br>E ',$str,1);
		        echo $str;
		        echo "<div class='zuoda' id='mao_".$row['id']."'>";
		        echo "<input class='bigger' onclick='duoxuan(this)' value='A' type='checkbox' name='d_".$row["id"]."' ".(strpos($row['daan'],"A")!==false?"checked":"").">A ";
		        echo "<input class='bigger' onclick='duoxuan(this)' value='B' type='checkbox' name='d_".$row["id"]."' ".(strpos($row['daan'],"B")!==false?"checked":"").">B ";
		        echo "<input class='bigger' onclick='duoxuan(this)' value='C' type='checkbox' name='d_".$row["id"]."' ".(strpos($row['daan'],"C")!==false?"checked":"").">C ";
		        echo "<input class='bigger' onclick='duoxuan(this)' value='D' type='checkbox' name='d_".$row["id"]."' ".(strpos($row['daan'],"D")!==false?"checked":"").">D ";
		        if(strpos($row["xuanxiang"],"E")!==false)
		        echo "<input class='bigger' onclick='duoxuan(this)' value='E' type='checkbox' name='d_".$row["id"]."' ".(strpos($row['daan'],"E")!==false?"checked":"").">E ";
		        echo "</div>";
		        $duoxuanstr.="_".$row['id'];
		    }
		    echo "<hr>";
		    $i++;
		}
		?>
	</div>
</div>
</body>
</html>
<script>
(function(){
	var sytime=<?php echo 5400-(strtotime(date("Y-m-d H:i:s",time()))-strtotime($pxsj['kaoshitime']))?>;
	var divsytime=document.getElementById("sytime");
	(function actiontime(sytime){
		divsytime.innerHTML="倒计时："+parseInt(sytime/60/60)+":"+parseInt(sytime/60%60)+":"+(sytime%60);
		if(sytime>5){
			setTimeout(function(){actiontime(--sytime)},1000);
		}else{
			tijiao(1);
		}
	})(sytime);
})();
function jiaojuan(){
	$.xconfirm("<font color='red' size='6'>是否确定交卷？</font>",function(tf){
		if(tf){
			$i=0;
			$.each($('.dati'),function(k,e){
				if(e.className.length>6||e.style.backgroundColor!=""){
					$i++;
				}
			});
			if($i<100){
				$.xcontent("<font color='red' size='6'>还有题没有作答，是否继续交卷？</font>"+
						"<div style='text-align:right;'><button onclick='tijiao(1)'>确定</button>&nbsp;&nbsp;<button onclick='tijiao(0)'>取消</button></div>");
			}else{
				tijiao(1);
			}
		}
	});
}
function tijiao(flog){
	$("#XPOPUPCONFIRM").remove();
	$("#XPOPUPCONFIRMC").remove();
	$("#XPOPUPCONTENT").remove();
	$("#XPOPUPCONTENTC").remove();
	var daan={
		    <?php
		    foreach ($pxst as $row){
		        echo "t_".$row['id'].":'".$row['biaozhundaan']."',";
		    }
		    ?>
		};
	if(flog==1){
		$duoxuan="<?php echo $duoxuanstr;?>";//id_1_2_3...
		var fenshu=0;
		var pdaan="pd";
		for(e in lS){
			if(e[0]=='p'){
				if(daan["t_"+e.split("_")[1]]==lS[e]){
					fenshu++;
				}
				pdaan+="_"+e.split("_")[1]+","+lS[e];
			}
		}
		var ddaan="dx";
		for(e of $duoxuan.split("_")){
			var duodaan="";
			if(e!="id"){
				$("input[name='d_"+e+"']:checked").each(function(){
					duodaan+=$(this).val();
	 			});
	 			if(duodaan==daan["t_"+e]){
					fenshu++;
		 		}
		 		ddaan+="_"+e+","+duodaan;
			}
		}
 		$.xpost("pxexam",{
 			type:"jiaojuan2",
			pxsjid:"<?php echo $pxsj['id']?>",
			pxxyid:"<?php echo $pxxy['id']?>",
			zhengbukao:"<?php echo $pxsj['zhengbukao']?>",
			idcard:"<?php echo $pxxy['idcard']?>",
			fenshu:fenshu,
 			daan:(pdaan+ddaan)
 		},function(data){
 			$.xloading(0);
 			$.xalert("<font color='red' size='7'>得分："+fenshu+"</font>",function(){
 				location.href="pxexam";
 			});
 		});
	}
}
function dati(ele){
	var divdati=document.getElementById("dati_"+ele.name.split("_")[1]);
	divdati.style.backgroundColor="#aaa";
	var send=function(){
		$.post("pxexam",{type:"dati",id:ele.name.split("_")[1],daan:ele.value},function(data){
    		console.log(ele.value);
    	}).error(function(){
    		send();
    	});
	}
	//send();//不用进行答题情况同步，超过50人服务器有点吃不消，想其他办法，如下
	lS.setItem(ele.name,ele.value);
}
(function(){//本地客服端存储答题信息，用于恢复考试中断后的数据
	sjid='<?php echo $_SESSION['pxsjid']?>';
	if(sjid!=lS.getItem("sjid")){
		lS.clear();
		lS.setItem("sjid",sjid);
	}else{
		for(e in lS){
			if(e[0]=='p'){
				$("input[name="+e+"]").xradioSelected(lS[e]);
				var divdati=document.getElementById("dati_"+e.split("_")[1]);
				divdati.style.backgroundColor="#aaa";
			}
		}
	}
})();
function duoxuan(ele){
	$ele=$("input[name='"+ele.name+"']");
	$flog=false;
	$.each($ele,function(k,e){
		if(e.checked){
			$flog=true;
		}
	});
	var divdati=document.getElementById("dati_"+ele.name.split("_")[1]);
	divdati.style.backgroundColor="";
	if($flog){
		divdati.style.backgroundColor="#aaa";
	}
}
function mao(t){
	t--;
	location.href="pxexam/type/exam#mao_"+t;
}
</script>